﻿Imports Microsoft.ApplicationBlocks.Data

Namespace DAL
    Public Class LinkProvider
        Inherits DataAccess
        Private util As New Utilities.Common()

        Public Sub New()

        End Sub

        Public Sub Create(ByVal l As MeoTom.Core.BLL.Link)
            Try
                Dim param(6) As SqlClient.SqlParameter
                param(0) = New SqlClient.SqlParameter("@LinkName", SqlDbType.NVarChar, 50)
                param(0).Value = l.LinkName
                param(1) = New SqlClient.SqlParameter("@LinkAddress", SqlDbType.NVarChar, 550)
                param(1).Value = l.LinkAddress
                param(2) = New SqlClient.SqlParameter("@LinkDesc", SqlDbType.NVarChar, 450)
                param(2).Value = l.LinkDesc
                param(3) = New SqlClient.SqlParameter("@TargetType", SqlDbType.Int, 4)
                param(3).Value = l.TargetType
                param(4) = New SqlClient.SqlParameter("@IsPrivate", SqlDbType.Int, 4)
                param(4).Value = l.IsPrivate
                param(5) = New SqlClient.SqlParameter("@SiteID", SqlDbType.Int, 4)
                param(5).Value = Configs.SiteID

                SqlHelper.ExecuteNonQuery(strConn, CommandType.StoredProcedure, "Justin_Link_Create", param)
            Catch ex As Exception
                Throw New Exception(ex.Message)
            End Try
        End Sub

        Public Sub Update(ByVal l As MeoTom.Core.BLL.Link)
            Try
                Dim param(7) As SqlClient.SqlParameter
                param(0) = New SqlClient.SqlParameter("@LinkName", SqlDbType.NVarChar, 50)
                param(0).Value = l.LinkName
                param(1) = New SqlClient.SqlParameter("@LinkAddress", SqlDbType.NVarChar, 550)
                param(1).Value = l.LinkAddress
                param(2) = New SqlClient.SqlParameter("@LinkDesc", SqlDbType.NVarChar, 450)
                param(2).Value = l.LinkDesc
                param(3) = New SqlClient.SqlParameter("@TargetType", SqlDbType.Int, 4)
                param(3).Value = l.TargetType
                param(4) = New SqlClient.SqlParameter("@IsPrivate", SqlDbType.Int, 4)
                param(4).Value = l.IsPrivate
                param(5) = New SqlClient.SqlParameter("@LinkID", SqlDbType.Int, 4)
                param(5).Value = l.LinkID
                param(6) = New SqlClient.SqlParameter("@SiteID", SqlDbType.Int, 4)
                param(6).Value = Configs.SiteID

                SqlHelper.ExecuteNonQuery(strConn, CommandType.StoredProcedure, "Justin_Link_Update", param)
            Catch ex As Exception
                Throw New Exception(ex.Message)
            End Try
        End Sub

        Public Sub Delete(ByVal l As MeoTom.Core.BLL.Link)
            Try
                Dim param(2) As SqlClient.SqlParameter
                param(0) = New SqlClient.SqlParameter("@LinkID", SqlDbType.Int, 4)
                param(0).Value = l.LinkID
                param(1) = New SqlClient.SqlParameter("@SiteID", SqlDbType.Int, 4)
                param(1).Value = Configs.SiteID

                SqlHelper.ExecuteNonQuery(strConn, CommandType.StoredProcedure, "Justin_Link_Delete", param)
            Catch ex As Exception
                Throw New Exception(ex.Message)
            End Try
        End Sub

        Public Function GetByID(ByVal l As MeoTom.Core.BLL.Link) As SqlClient.SqlDataReader
            Dim param(2) As SqlClient.SqlParameter
            param(0) = New SqlClient.SqlParameter("@LinkID", SqlDbType.Int, 4)
            param(0).Value = l.LinkID
            param(1) = New SqlClient.SqlParameter("@SiteID", SqlDbType.Int, 4)
            param(1).Value = Configs.SiteID

            Return SqlHelper.ExecuteReader(strConn, CommandType.StoredProcedure, "Justin_Link_GetByID", param)
        End Function

        Public Function GetAll(ByVal l As MeoTom.Core.BLL.Link) As Data.DataSet
            Dim param(2) As SqlClient.SqlParameter
            param(0) = New SqlClient.SqlParameter("@LinkCat", SqlDbType.Int, 4)
            param(0).Value = l.LinkCat
            param(1) = New SqlClient.SqlParameter("@SiteID", SqlDbType.Int, 4)
            param(1).Value = Configs.SiteID

            Return SqlHelper.ExecuteDataset(strConn, CommandType.StoredProcedure, "Justin_Link_getAll", param)
        End Function

        Public Function GetAllCat(ByVal l As MeoTom.Core.BLL.Link) As SqlClient.SqlDataReader
            Dim param(2) As SqlClient.SqlParameter
            param(0) = New SqlClient.SqlParameter("@LinkID", SqlDbType.Int, 4)
            param(0).Value = l.LinkID
            param(1) = New SqlClient.SqlParameter("@SiteID", SqlDbType.Int, 4)
            param(1).Value = Configs.SiteID

            Return SqlHelper.ExecuteReader(strConn, CommandType.StoredProcedure, "Justin_Link_GetAllCat", param)
        End Function

        Public Sub SetTempLinkCat(ByVal l As MeoTom.Core.BLL.Link, ByVal type As Integer)
            Try
                Dim param(3) As SqlClient.SqlParameter
                param(0) = New SqlClient.SqlParameter("@CatID", SqlDbType.Int, 4)
                param(0).Value = l.LinkCat
                param(1) = New SqlClient.SqlParameter("@Type", SqlDbType.Int, 4)
                param(1).Value = type
                param(2) = New SqlClient.SqlParameter("@LinkID", SqlDbType.Int, 4)
                param(2).Value = l.LinkID

                SqlHelper.ExecuteNonQuery(strConn, CommandType.StoredProcedure, "Justin_Link_SetTempLinkCat", param)
            Catch ex As Exception
                Throw New Exception(ex.Message)
            End Try
        End Sub

        Public Sub RemoveTempLinkCat(ByVal l As MeoTom.Core.BLL.Link)
            Try
                Dim param(1) As SqlClient.SqlParameter
                param(0) = New SqlClient.SqlParameter("@LinkID", SqlDbType.Int, 4)
                param(0).Value = l.LinkID

                SqlHelper.ExecuteNonQuery(strConn, CommandType.StoredProcedure, "Justin_Link_RemoveTempLinkCat", param)
            Catch ex As Exception
                Throw New Exception(ex.Message)
            End Try
        End Sub
    End Class
End Namespace
